package com.woniuxy.Test;

import com.woniuxy.intface.Person;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * @Author：向天浩
 * @Date：2022/1/17 19:46
 * @Description :Spring的解耦
 */

public class SpringTest {
    public static void main(String[] args) {
        //spring的工厂
        //方式1；new XmlBeanFactory(new ClassPathResource("Person.xml"));
//        BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource("Person.xml"));
//        Person ch = (Person) beanFactory.getBean("ch");
//        Person am = (Person) beanFactory.getBean("am");
//        ch.eat();
//        am.eat();

        //方式2；new FileSystemXmlApplicationContext()这个使用的文件绝对路径
//        ApplicationContext ApplicationContext=new FileSystemXmlApplicationContext("E:\\java85classcode\\类与类解耦\\src\\Person.xml");
//        Person ch = (Person) ApplicationContext.getBean("ch");Person.class
//        ch.eat();

        //方式3；new ClassPathXmlApplicationContext("Person.xml");
        ApplicationContext ApplicationContext=new ClassPathXmlApplicationContext("Person.xml");
        Person am = ApplicationContext.getBean("am", Person.class);
        am.eat();
    }
}
